/**
 * Created by vivienfanghua on 2016/7/26.
 */
var _       = require('lodash');
var helpers = require('./_helpers');
var orm     = require('../../../../');
var messageCode=require('../../config/code');
module.exports = {
    list:function(req,res){
        req.models.hospital.find().limit(15).order('id').all(function (err, hospitals) {
            if (err) {
                return res.send({message:messageCode.list_hospital_fail});
        }

            var items = hospitals.map(function (m) {
                return m.serialize();
            });
             res.send({message:messageCode.list_hospital_success,data:items});
         //   return res.send({message:messageCode.list_hospital_success,data:JSON.stringify({ items: items}});
          //  res.send(JSON.stringify({ items: items}));
        });
        //res.send('This is hospital list!');
    },
    load:function(req,res){
        var param=req.query.hospital_id;
        //var param =req.body['hospital_id'];
        console.log("%s is found",param);
        res.send('Load hospital done!');
    },
    create:function(req,res){
        var params = _.pick(req.body, 'name', 'disc');
        var data={body:'这是一条牛逼的评论',createdAt:'2016-07-25 23:37:50',message_id:1};
        req.models.comment.create(data,function (err, message) {
            if(err) {
                return res.send(err);
            }
            return res.send(200, message.serialize());
        });
        //console.log("%s is created, the description is %s",params.name,params.disc);
        //res.send('Create hospital done!');
    }
}
